package com.bjdd.jdy.base;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.bjdd.jdy.R;
import com.bjdd.jdy.util.TUtil;
import com.umeng.analytics.MobclickAgent;

import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/4/18.
 */

public abstract class BaseFragment<P extends BasePresenter,M extends BaseModel> extends Fragment {
    private View view;

    public P presenter;
    public M model;

    public Context context;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(getLayoutId(), container, false);
        ButterKnife.bind(this, view);
        context = getContext();
        presenter = TUtil.getT(this,0);
        model = TUtil.getT(this,1);
        if(this instanceof BaseView) presenter.setVM(context,this,model);
        //ImmersionBar.with(this).init();
        initView();
        return view;
    }

    public abstract int getLayoutId();
    public abstract void initView();

    @Override
    public void onDestroy() {
        super.onDestroy();
        if(presenter != null){
            presenter.onDestroy();
        }
        //ImmersionBar.with(this).destroy();
        ButterKnife.unbind(this);
    }

    @Override
    public void onResume() {
        super.onResume();
        presenter.onResume();
        MobclickAgent.onPageStart(getClass().getSimpleName());
    }

    @Override
    public void onPause() {
        super.onPause();
        MobclickAgent.onPageEnd(getClass().getSimpleName());
    }
}
